package com.Index;

import com.ChessUtils.ChessUtil;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

/**
 * @author acoffee
 * @create 2021-08-31 19:40
 */
public class GameIndexView extends Stage {

    //按钮尺寸
    private int btnLength = 100;

    //按钮位置参数
    private int btnPos = 50;

    public GameIndexView() {
        setTitle("Acoffee的五子棋");
        //窗体不能修改
        setResizable(false);

        //获取画板对象
        Pane pane = getPane();

        //设置幕布大小
        Scene scene = new Scene(pane, 400, 200);

        setScene(scene);
    }

    public Pane getPane() {

        //创建画板对象
        Pane pane = new Pane();

        //创建一个首页功能对象
        IndexButtonService indexButtonService = new IndexButtonService();

        //给画板对象设置背景颜色
        pane.setBackground(new Background(new BackgroundImage(new Image("/background.jpg"), null, null, null, null)));

        //创建一个功能对象
        addBtn(pane, indexButtonService);

        return pane;
    }

    private void addBtn(Pane pane, IndexButtonService indexButtonService) {

        //创建五子棋单机版选择按钮
        Button singleBtn = ChessUtil.getButton("单机版", btnLength, btnLength, btnPos, btnPos);

        //创建五子棋对战版选择按钮
        Button buttleBtn = ChessUtil.getButton("对战版", btnLength, btnLength, btnPos * 5, btnPos);

        indexButtonService.singleBtnAction(singleBtn, this);
        indexButtonService.buttleBtnAction(buttleBtn, this);

        pane.getChildren().addAll(singleBtn, buttleBtn);
    }
}
